找传奇、传世资源到传世资源站!

WCF 权限验证 实例源码下载

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

wcf 自定义权限验证调用完整例子源码

static void Main(string[] args){ Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN"); ChannelFactory<ICalculator> channelFactory = new ChannelFactory<ICalculator>("calculatorService"); NetworkCredential credential = channelFactory.Credentials.Windows.ClientCredential; credential.UserName = "Foo"; credential.Password = "Password"; ICalculator calculator = channelFactory.CreateChannel(); Invoke(proxy => proxy.Add(1, 2), calculator, "Add"); Invoke(proxy => proxy.Subtract(1, 2), calculator, "Subtract"); Invoke(proxy => proxy.Multiply(1, 2), calculator, "Multiply"); Invoke(proxy => proxy.Divide(1, 2), calculator, "Divide"); Console.WriteLine(); channelFactory = new ChannelFactory<ICalculator>("calculatorService"); credential = channelFactory.Credentials.Windows.ClientCredential; credential.UserName = "Bar"; credential.Password = "Password"; calculator = channelFactory.CreateChannel(); Invoke(proxy => proxy.Add(1, 2), calculator, "Add"); Invoke(proxy => proxy.Subtract(1, 2), calculator, "Subtract"); Invoke(proxy => proxy.Multiply(1, 2), calculator, "Multiply"); Invoke(proxy => proxy.Divide(1, 2), calculator, "Divide"); Console.Read();}static void Invoke(Action<ICalculator> action, ICalculator proxy, string operation){ try { action(proxy); Console.WriteLine("服务操作\"{0}\"调用成功...", operation); } catch (Exception ex) { Console.WriteLine("服务操作\"{0}\"调用失败...", operation); }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复